summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockPlant.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blocks/BlockPlant.h')
-rw-r--r--src/Blocks/BlockPlant.h80
1 files changed, 48 insertions, 32 deletions
diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h
index bab34f798..02092fc38 100644
--- a/src/Blocks/BlockPlant.h
+++ b/src/Blocks/BlockPlant.h
@@ -1,25 +1,30 @@
-// BlockPlant.h
-
-// Base class for any growing block
-
+#pragma once
+#include "BlockHandler.h"
-#pragma once
-#include "BlockHandler.h"
-class cBlockPlant : public cBlockHandler
+/** Base class for plants that use light values to decide whether to grow or not. */
+template <bool NeedsLightToGrow>
+class cBlockPlant:
+ public cBlockHandler
{
- typedef cBlockHandler Super;
- bool m_NeedLightToGrow;
+ using super = cBlockHandler;
+
public:
- cBlockPlant(BLOCKTYPE a_BlockType, bool a_LightToGrow)
- : Super(a_BlockType), m_NeedLightToGrow(a_LightToGrow){}
+
+ cBlockPlant(BLOCKTYPE a_BlockType):
+ super(a_BlockType)
+ {
+ }
+
protected:
+
+ /** The action the plant can take on an update. */
enum PlantAction
{
paDeath,
@@ -27,6 +32,10 @@ protected:
paStay
};
+
+
+
+
/** Checks whether there is enough light for the plant to grow.
If the plant doesn't require light to grow, then it returns paGrowth.
If the plant requires light to grow and there is enough light, it returns paGrowth.
@@ -37,34 +46,37 @@ protected:
{
// If the plant requires light to grow, check to see if there is enough light
// Otherwise, return true
- if (m_NeedLightToGrow)
+ if (!NeedsLightToGrow)
{
- NIBBLETYPE Blocklight = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ);
- NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelX, a_RelY, a_RelZ);
- NIBBLETYPE Light = a_Chunk.GetTimeAlteredLight(SkyLight);
-
- // If the amount of light provided by blocks is greater than the sky light, use it instead
- if (Blocklight > Light)
- {
- Light = Blocklight;
- }
+ return paGrowth;
+ }
+ NIBBLETYPE Blocklight = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ);
+ NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelX, a_RelY, a_RelZ);
+ NIBBLETYPE Light = a_Chunk.GetTimeAlteredLight(SkyLight);
- // Based on light levels, decide between growth, stay and death:
- if (Light > 8)
- {
- return paGrowth;
- }
- else if ((Blocklight < 9) && (SkyLight < 9))
- {
- return paDeath;
- }
+ // If the amount of light provided by blocks is greater than the sky light, use it instead
+ if (Blocklight > Light)
+ {
+ Light = Blocklight;
+ }
- return paStay;
+ // Based on light levels, decide between growth, stay and death:
+ if (Light > 8)
+ {
+ return paGrowth;
+ }
+ else if ((Blocklight < 9) && (SkyLight < 9))
+ {
+ return paDeath;
}
- return paGrowth;
+ return paStay;
}
+
+
+
+
/** Checks whether a plant can grow grow, based on what is returned from cBlockPlant::HasEnoughLight
and a random check based on what is returned from cBlockPlant::GetGrowthChance.
Can return three values.
@@ -84,6 +96,10 @@ protected:
return Action;
}
+
+
+
+
/** Generates a int value between 4 and 25 based on surrounding blocks that affect how quickly the plant grows.
The higher the value, the less likely the plant is to grow */
virtual int GetGrowthChance(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ)